<?php
!function_exists('html') && exit('ERR');
if($job=='list'&&$Apower[smallpic])
{
	hack_admin_tpl('list');
}
if ($action=='do'&&$Apower[smallpic]){
	if ($p<1){
		$p = 0;
	}
	$rows = 100;
	$min = $p * $rows;
	$query = $db->query("SELECT A.content,A.aid,A.fid FROM {$pre}article B LEFT JOIN {$pre}reply A ON A.aid = B.aid WHERE B.mid=0 LIMIT $min,$rows");
	while ($rs = $db->fetch_array($query)){
		$str = En_TruePath($rs[content],0);
	    $array = get_content_attachment($str);
	    if ($array[0]){
	    	foreach ($array as $val){
	    		if (strrchr($val,'.')=='.gif' || strrchr($val,'.')=='.jpg' || strrchr($val,'.')=='png'){
	    			if (file_exists(ROOT_PATH."$webdb[updir]/$val.jpg")){
				    	if ($isCover){
				    		if (file_exists(ROOT_PATH."$webdb[updir]/$val")){
				    			gdpic(ROOT_PATH."$webdb[updir]/$val", ROOT_PATH."$webdb[updir]/$val.jpg.jpg", 150, 120,$isFill);
				    			gdpic(ROOT_PATH."$webdb[updir]/$val", ROOT_PATH."$webdb[updir]/$val.jpg", 150, 150,$isFill);
				    			gdpic(ROOT_PATH."$webdb[updir]/$val", ROOT_PATH."$webdb[updir]/$val.jpg.jpg.jpg", 120, 150,$isFill);
				    			$picurl = "article/$rs[fid]/{$lfjuid}_".basename($val).".jpg";
			    				break;
				    		}
				    	}
				    }else {
				    	gdpic(ROOT_PATH."$webdb[updir]/$val", ROOT_PATH."$webdb[updir]/$val.jpg.jpg", 150, 120,$isFill);
				    	gdpic(ROOT_PATH."$webdb[updir]/$val", ROOT_PATH."$webdb[updir]/$val.jpg", 150, 150,$isFill);
				    	gdpic(ROOT_PATH."$webdb[updir]/$val", ROOT_PATH."$webdb[updir]/$val.jpg.jpg.jpg", 120, 150,$isFill);
				    	$picurl = "article/$rs[fid]/{$lfjuid}_".basename($val).".jpg";
			    		break;
				    }
	    		}
	    	}
	    }else {
	    	preg_match_all("/http:\/\/([^ '\"<>]+)\.(gif|jpg|png)/is",$rs[content],$arr);
	    	if ($arr[0][0]){
	    		$pic=ROOT_PATH."$webdb[updir]/{$lfjuid}_".basename($arr[0][0]);
	    		if ($isCopy){
	    			copy($arr[0][0], $pic);
	    		}
	    		gdpic($arr[0][0],"$pic",150,150,$isFill);
	    		if (!file_exists(ROOT_PATH."$webdb[updir]/article/$rs[fid]/")){
	    			makepath(ROOT_PATH."$webdb[updir]/article/$rs[fid]/");
	    		}
				copy($pic,ROOT_PATH."$webdb[updir]/article/$rs[fid]/{$lfjuid}_".basename($arr[0][0]).".jpg");
				if(!$isCopy){
					unlink($pic);
				}
				$picurl = "article/$rs[fid]/{$lfjuid}_".basename($arr[0][0]).".jpg";
	    	}
	    }
	    $i++;
	    $db->update("UPDATE {$pre}article SET picurl = '{$picurl}',ispic = 1 WHERE aid = {$rs[aid]}");
	}
	if (!$i){
		echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
		echo "<A HREF='?lfj={$lfj}&job=list'>专题静态页生成完毕,请点击返回</A>";
		exit;
	}
	$p= $p+ 1;
	echo "请稍候,正在生成图片缩略图$p...<META HTTP-EQUIV=REFRESH CONTENT='0;URL=?lfj={$lfj}&action={$action}&isCover={$isCover}&isCopy={$isCopy}&isFill={$isFill}&p=$p'> ";
}
?>